﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BEELab
{
    public partial class Main : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string sessions = "";
            foreach (int i in Global.BlockElementsDictionary.Keys)
            {
                if (sessions == "")
                {
                    sessions = i.ToString();
                }
                else
                {
                    sessions += ", " + i;
                }
            }

            if (sessions.Length > 0)
                SqlDataSource3.SelectCommand = "SELECT * FROM Sessions JOIN Programs ON Sessions.ProgramID=Programs.ID WHERE (OwnerID=" + Session["UserID"].ToString() + "OR 'True'='" + Session["Admin"].ToString() + "') AND Sessions.ID IN (" + sessions + ")";
        }

        protected void gvSession_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (Global.LastSessionActivity.ContainsKey(int.Parse(e.Row.Cells[3].Text)))
                {
                    e.Row.Cells[3].Text = Global.LastSessionActivity[int.Parse(e.Row.Cells[3].Text)].ToString();
                }
                else
                {
                    e.Row.Cells[3].Text = "Never";
                }
            }
        }

    }
}